<template>
	<view class="content" :style="{'padding-top':paddingTop+'px'}">
		<Nav title="Ai笑" title1="记录你的美好瞬间" bgColor="#d86784" :backIcon="false" style="color: #ffffff;z-index: 1;"></Nav>
		<view class="search" :style="{top:top+'px'}">
			<uni-easyinput placeholder="搜索图片、文章、视频" prefixIcon="search"></uni-easyinput>
			<button size="mini">搜索</button>
		</view>
		<view class="left">
			<view class="withbeat" @click="onShootDetail(item.id)" v-for="item in leftlist" :key="item.id">
				<image :src="item.blogImgUrl" mode="aspectFill" class="cover" :style="{height:item.imageheight+'px'}"></image>
				<view class="beattext">{{item.blogTitle}}</view>
				<view class="details">
					<view class="user">
						<image :src="item.avatarUrl" mode="aspectFill"></image>
						<text class="name">{{item.nickname}}</text>
					</view>
					<view :class="item.thumb===true ? 'likeselect' : 'givealike'">
						<uni-icons :type="item.thumb===true ? 'hand-up-filled' : 'hand-up'" ></uni-icons>
						<text class="OfLikes">{{item.blogLikeNum}}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="right">
			<view class="withbeat" @click="onShootDetail(item.id)" v-for="item in rightlist" :key="item.id">
				<image :src="item.blogImgUrl" mode="aspectFill" class="cover" :style="{height:item.imageheight+'px'}"></image>
				<view class="beattext">{{item.blogTitle}}</view>
				<view class="details">
					<view class="user">
						<image :src="item.avatarUrl" mode="aspectFill"></image>
						<text class="name">{{item.nickname}}</text>
					</view>
					<view :class="item.thumb===true ? 'likeselect' : 'givealike'">
						<uni-icons :type="item.thumb===true ? 'hand-up-filled' : 'hand-up'"></uni-icons>
						<text class="OfLikes">{{item.blogLikeNum}}</text>
					</view>
				</view>
			</view>
		</view>
		<Tabbar :page="page"></Tabbar>
	</view>
</template>

<script setup>
	import {
		onMounted,
		ref
	} from 'vue'
	import {
		onShow,
		onLoad,
		onPullDownRefresh
	} from '@dcloudio/uni-app'
	const blogurl = getApp().globalData.blogurl
	const title = ref('Hello')
	const page = ref('/pages/index/index')
	const platform = ref()
	const statusBar = ref()
	const customBar = ref()
	const top = ref()
	const paddingTop = ref()
	const leftlist=ref([])
	const rightlist=ref([])
	const Overalllist=ref([])
	const coverwidth=ref()
	const onShootDetail = (id) => {
		uni.navigateTo({
			url: "/pages/onShootDetail/onShootDetail?id="+id
		})
	}
	const getColumnHeight=()=>{
		uni.getSystemInfo({
			success(res) {
				coverwidth.value=res.windowWidth*0.48-10
				platform.value = res.platform
				// #ifdef MP-WEIXIN
				statusBar.value = res.statusBarHeight
				const custom = wx.getMenuButtonBoundingClientRect()
				customBar.value = custom.bottom + custom.top - res.statusBarHeight
				// #endif
				// #ifdef APP-PLUS
				statusBar.value = res.statusBarHeight
				customBar.value = res.statusBarHeight + 45
				// 这里是在安卓手机上加上 3 像素（当时好像是在安卓水滴屏上，系统导航栏高度较低才加上去的，大家可以真机自己调试一下）
				if (res.platform == "android") {
					statusBar.value += 3
					customBar.value += 3
				}
				// #endif
			}
		})
		top.value = statusBar.value * 2 + (customBar.value - statusBar.value) * 2 - 2
		top.value=top.value/2
		paddingTop.value = top.value + 50
		//console.log(statusBar.value, customBar.value, top.value)
	}
	onPullDownRefresh(() => {
		console.log(1)
		setTimeout(() => {
			uni.stopPullDownRefresh();
		}, 1000);
	})
	onMounted(()=>{
		getColumnHeight()
	})
	onShow(()=>{
		getColumnHeight()
		const now = new Date().getTime()
		// if (!uni.getStorageSync('token') || now > uni.getStorageSync('expireTime')) {
		// 	uni.reLaunch({
		// 		url: "/pages/login/login"
		// 	})
		// }else{
			console.log(uni.getStorageSync('token'))
			leftlist.value=[]
			rightlist.value=[]
			uni.request({
				url: blogurl + "/list",
				method: "POST",
				dataType: "json",
				header: {
					'content-type': 'application/json',
					'Access-Control-Allow-Origin': "*",
					'Authorization': uni.getStorageSync('token')
				},
				data: {
					//photographerId: getApp().globalData.user.id
				},
				success: function(res) {
					console.log(res)
					Overalllist.value=res.data.value
					for(let i=0;i<Overalllist.value.length;i++){
						uni.getImageInfo({
							src:Overalllist.value[i].blogImgUrl,
							success:function(image){
								//console.log(image)
								//console.log(image.height/image.width*coverwidth.value)
								Overalllist.value[i].imageheight=image.height/image.width*coverwidth.value
								//console.log(Overalllist.value)
							}
						})
						if(i%2===0){
							leftlist.value.push(Overalllist.value[i])
						}else{
							rightlist.value.push(Overalllist.value[i])
						}
					}
					//console.log(rightlist.value,leftlist.value)
				}
			})
		//}
	})
</script>

<style lang="less">
	.content {
		padding-top: 268rpx;
		padding-bottom: 100px;
		display: flex;
		//align-items: flex-start;
		//flex-wrap: wrap;
		min-height: calc(100vh - 468rpx);
		background-image: linear-gradient(to bottom, #d95e7d, #ffffff);
	}

	.search {
		position: fixed;
		//top: 168rpx;
		width: 100%;
		height: 50px;
		background-color: #d86784;
		display: flex;
		align-items: center;
		justify-content: space-evenly;

		button {
			margin-right: 30rpx;
			border-radius: 30rpx;
			background-color: #e77c90;
			color: #ffffff;
			height: 60rpx;
			line-height: 60rpx;
		}
	}

	.custom-navigation-bar {
		display: flex;
		align-items: center;
		justify-content: space-between;
		height: 96rpx;
	}

	.left {
		width: 48%;
		margin-left: 10rpx;
	}

	.right {
		width: 48%;
		margin-left: 10rpx;
	}

	.withbeat {
		padding: 10rpx;
		box-sizing: border-box;
		width: 100%;
		height: auto;
		background-color: #eeeeee;
		border-radius: 30rpx;
		margin-top: 15rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		.cover{
			min-height: 240rpx;
		}
		image {
			width: 100%;
			height: 500rpx;
			border-radius: 30rpx;
		}
	}


	.beattext {
		width: 90%;
		//height: 84rpx;
		overflow-wrap: break-word;
	}

	.details {
		width: 90%;
		height: 38rpx;
		vertical-align: middle;
		display: flex;
		align-items: center;
		justify-content: space-between;
		.user{
			display: flex;
			align-items: center;
		}
		image {
			width: 38rpx;
			height: 38rpx;
			border-radius: 50%;
			background-color: #dddddd;
		}
		.givealike{
			height: 40rpx;
			vertical-align: middle;
			display: flex;
			align-items: center;
			color: #000000;
			.uni-icons{
				font-size: 40rpx !important;
				color: #000000 !important;
			}
		}
		.likeselect{
			height: 40rpx;
			vertical-align: middle;
			display: flex;
			align-items: center;
			color: red;
			.uni-icons{
				font-size: 40rpx !important;
				color: red !important;
			}
			
		}
		.name {
			margin-left: 10rpx;
			display: inline-block;
			font-size: 28rpx;
			height: 38rpx;
			line-height: 38rpx;
		}
		.OfLikes {
			display: inline-block;
			font-size: 28rpx;
			height: 40rpx;
			line-height: 40rpx;
		}
	}

	/deep/.uni-easyinput__content {
		border-radius: 40rpx !important;
		width: 550rpx !important;
		height: 60rpx !important;
		background-color: #ffffff !important;
		border: #ffffff solid 2rpx !important;
		color: #ffffff !important;
		margin-left: 30rpx;
	}
</style>